<template>
  <div>
    <el-breadcrumb separator="/" style="height:30px">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>分类管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{path:'/categorylist'}">分类列表</el-breadcrumb-item>
      <el-breadcrumb-item>添加分类</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form :model="category" style="margin-top:30px" label-width="80px">
      <el-form-item label="新闻类别">
        <el-input v-model="category.name" placeholder="请输入类别名称" style="width: 200px;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addCategoryFu">添加</el-button>
        <el-button @click="category={}">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { addCategory } from "../../api";
export default {
  data() {
    return {
      category: {}
    };
  },
  methods: {
    // 添加分类
    async addCategoryFu() {
      let { data } = await addCategory(this.category);
      if (data.code == 1) {
        this.$router.push('/categoryList')
        this.$message.success("添加成功");
      } else {
        this.$message.error("添加失败");
      }
    }
  }
};
</script>

<style>
</style>